<template>
	<view class="order tn-safe-area-inset-bottom">

		<!-- 顶部自定义导航开始 -->
		<view class="tn-navbg" :style="{height: vuex_custom_bar_height + 'px'}">
			<!-- 顶部自定义导航 -->
			<tn-nav-bar fixed alpha customBack>
				<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
					<text class='icon tn-icon-left'></text>
					<text class='icon tn-icon-home-capsule-fill'></text>
				</view>
				<view class="tn-flex tn-flex-col-center tn-flex-row-center ">
					<text class="tn-text-bold tn-text-xl tn-color-black">答题历史</text>
				</view>
			</tn-nav-bar>
		</view>
		<!-- 顶部自定义导航结束 -->
		<view class="" v-if="collectionList.length > 0">
			<!-- 试题列表开始 -->
			<view class="tn-padding-bottom-xl">
				<block v-for="(item, index) in collectionList" :key="index">
					<view class="home-shadow tn-margin" @click="tn('/subpages/exam/history/detail?uid=' + item.uid)">
						<view class="tn-flex">
							<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
								<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
									<text class="">{{ item.title }}</text>
								</view>
								<view class="tn-padding-top-xs" style="min-height: 90rpx;">
									<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
										<!-- {{ item.remark }} -->
									</text>
								</view>
								<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-xs">
									<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm">
										<text class="tn-icon-menu-match tn-padding-right-xs tn-text-lg tn-color-blue"></text>
										<text class="tn-text-df">共 {{ item.exam_count }} 题</text>
									</view>
									<view class="justify-content-item tn-color-gray tn-text-center tn-color-gray"
										style="padding-top: 5rpx;">
										<text class="tn-icon-check tn-padding-right-xs tn-text-lg tn-color-green"></text>
										<text class="tn-padding-right tn-text-df tn-color-green">{{ item.correct_count }}</text>
										<text class="tn-icon-close tn-padding-right-xs tn-text-lg tn-color-red"></text>
										<text class="tn-text-df tn-color-red">{{ item.error_count }}</text>
									</view>
								</view>
							</view>
							<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.image + ')'">
								<view class="image-article">
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<!-- 试题列表结束 -->
			<tn-load-more :status="loadStatus"></tn-load-more>
		</view>

		<view class="" v-if="collectionList.length == 0">
			<view class="" style="padding: 15vh 20rpx;">
				<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
					<text class="tn-icon-empty-page tn-color-gray--light"></text>
				</view>
				<view class="tn-color-gray--disabled tn-text-center tn-text-lg">您还未参加任何答题</view>
			</view>
		</view>

		<view class='tn-tabbar-height'></view>


	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import {
		getSubmitHisotyList
	} from "@/utils/api/exam.js"
	export default {
		name: 'Comm',
		mixins: [template_page_mixin],
		data() {
			return {
				loadStatus: 'loading',
				collectionList: [],
				searchWhere: { // 试卷查询条件
					page: 1,
					size: 20,
				},
			}
		},
		onShow() {
			this.getSubmitHisotyList()
		},
		methods: {
			// 获取试卷列表
			getSubmitHisotyList(type = 1) {
				if (this.loadStatus === 'nomore') {
					return
				}
				uni.showLoading({
					title:"努力加载中",
					mask:true,
				})
				getSubmitHisotyList(this.searchWhere).then(res => {
					uni.hideLoading()
					if (res.code == 100) {
						this.collectionList.push(...res.data.items)
						this.searchWhere.page = res.data.page + 1
						if (this.collectionList.length == res.data.count) {
							this.loadStatus = "nomore"
						} else {
							this.loadStatus = "loadmore"
						}
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 跳转
			tn(e) {
				this.$func.navigatorTo(e)
			},
		},
		onReachBottom() {
			this.getSubmitHisotyList()
		}
	}
</script>

<style lang="scss" scoped>
	.order {
		max-height: 100vh;
	}

	.collection-remark {
		font-size: 24rpx;
	}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}
	// 胶囊结束

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	/* 阴影 start*/
	.home-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}


	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 试题列表图片 start*/
	.image-article {
		border-radius: 8rpx;
		width: 220rpx;
		height: 120rpx;
		position: relative;
	}

	.image-design {
		padding: 140rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	// 试题列表图片结束
</style>